package com.lhb.service.Impl;

import com.lhb.dao.Repository.RotationResporsitory;
import com.lhb.dao.RotationDao;
import com.lhb.pojo.BaseResp;
import com.lhb.pojo.RotationImage;
import com.lhb.service.RotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.10.14 下午 23:52
 */
@Service
public class RotationServiceImpl implements RotationService {

    @Autowired
    RotationDao rotationDao;

    @Autowired
    RotationResporsitory rotationResporsitory;


    @Override
    public BaseResp findAll(Integer page, Integer limit) {
        PageRequest of = PageRequest.of(page - 1, limit);
        Page<RotationImage> all = rotationResporsitory.findAll(of);
        BaseResp baseResp = new BaseResp();
        baseResp.setCode(0);
        baseResp.setMsg("success");
        baseResp.setCount(all.getTotalElements());
        baseResp.setData(all.getContent());
        return baseResp;
    }

    @Override
    public void del(Integer id) {
        rotationResporsitory.deleteById(id);
    }

    @Override
    public BaseResp updateRotation(RotationImage rotationImage) {
        int i = rotationDao.updateRotation(rotationImage);
        BaseResp baseResp = new BaseResp();
        baseResp.setCode(0);
        baseResp.setMsg("修改成功");
        return baseResp;
    }

    @Override
    public BaseResp insertRotation(RotationImage rotationImage) {
        int i = rotationDao.insertRotation(rotationImage);
        BaseResp baseResp = new BaseResp();
        baseResp.setCode(0);
        baseResp.setMsg("添加成功");
        return baseResp;
    }
}
